<template>
	<view style="width: 90%;margin: auto;margin-top: 100rpx">
    <uni-forms ref="valiForm" label-width="80" :rules="rules" :modelValue="feedBack">
      <uni-forms-item label="反馈类型" required name="feedBackType">
        <uni-data-checkbox mode="tag" multiple v-model="feedBack.feedBackType" :localdata="feedBackTypeList"></uni-data-checkbox>
      </uni-forms-item>
      <uni-forms-item label="反馈内容" required name="content">
        <uni-easyinput type="textarea" v-model="feedBack.content" placeholder="请输入反馈信息" />
      </uni-forms-item>
      <uni-forms-item label="联系人" required name="contacts">
        <uni-easyinput v-model="feedBack.contacts" placeholder="请输入联系人" />
      </uni-forms-item>
      <uni-forms-item label="联系方式" required name="contactMethod">
        <uni-easyinput v-model="feedBack.contactMethod" placeholder="请输入联系方式" />
      </uni-forms-item>
    </uni-forms>
    <button type="primary" @click="submit('valiForm')">提交</button>
	</view>
</template>

<script>
import {getDict} from '@/api/utils.js'
import {FeedbackService} from "./feedbackService";

export default {
		data() {
			return {
        feedBack:{
          feedBackType:[],
          content:"",
          contacts:"",
          contactMethod:"",
        },
        feedBackTypeList:[],
        // 校验规则
        rules: {
          content: {
            rules: [{
              required: true,
              errorMessage: '反馈信息不能为空'
            }]
          },
          contacts: {
            rules: [{
              required: true,
              errorMessage: '联系人不能为空'
            }]
          },
          contactMethod: {
            rules: [{
              required: true,
              errorMessage: '联系方式不能为空'
            }]
          }
        },
			}
		},
    mounted() {
      getDict("反馈类型").forEach(item => {
        this.feedBackTypeList.push({text:item.dictName,value:item.dictName})
      })
    },
		methods: {
      submit(ref) {
        this.$refs[ref].validate().then(res => {
          let data=JSON.parse(JSON.stringify(this.feedBack));
          data.feedBackType= data.feedBackType.join(",");
          FeedbackService.saveFeedback(data).then(res=>{
            if(res.statusCode==200){
              uni.showToast({
                title: `操作成功`
              })
              this.feedBack={}
            }
          })
        }).catch(err => {
          console.log('err', err);
        })
      },
		}
	}
</script>

<style>

</style>
